/* Copyright 2010 by Matt Van Der Westhuizen */

package org.chaoticengine.ast.view;

import org.newdawn.slick.Color;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

/**
 *
 * @author Matt Van Der Westhuizen <mattpwest@gmail.com>
 */
@Root(name="tile")
public class Tile {
    protected String imgFilename = "";
    protected Image img = null;
    protected Color color = Color.black;
    protected String path = "";

    public Tile() {}

    @Element(name="color")
    public Color getColor() {
        return color;
    }

    @Element(name="color")
    public void setColor(Color color) {
        this.color = color;
    }

    @Attribute(name="image")
    public String getImageFilename() {
        return imgFilename;
    }

    @Attribute(name="image")
    public void setImageFilename(String imgFilename) {
        this.imgFilename = imgFilename;
    }

    public Image getImage() {
        return img;
    }

    public void loadImage(String path) {
        try {
            this.img = new Image(path + imgFilename);
        } catch (SlickException sEx) {
            System.out.println("Warning: Failed to load tileset image '" + path + imgFilename + "'!");
        }
    }
}